package singleton;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:咭咭熊
 * Date:2021 - 08 - 27
 * Time:10:19
 */

import com.sun.xml.internal.ws.server.SingletonResolver;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.LockSupport;

/***
 * 设计一个类，只能生成该类的一个实例
 * 适用于多线程的环境，但效率不高
 * 为了保证在多线程的环境下，我们还是只能得到类型的恶一个实例，需要加上一个同步锁；
 */
public class Singleton2 {
    private Singleton2(){

    }
    private static Singleton2 instance = null;

    private static  Singleton2 getInstance(){
        if(instance == null){
            synchronized (Singleton2.class){
                instance = new Singleton2();
            }
        }
        return  instance;
    }
}
